//
//  GQHomeSearchController.m
//  GuQu
//
//  Created by HELIUM STAR on 15/5/11.
//  Copyright (c) 2015年 HELIUM STAR. All rights reserved.
//

#import "GQHomeSearchController.h"
#import "GQHomeSearchBar.h"
#define kSearchMargin 10

@interface GQHomeSearchController ()

@property (weak, nonatomic) UITextField *searchBar;
@property (weak, nonatomic) UIView *coverView;

@end

@implementation GQHomeSearchController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *rightItem = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 10)];
    [rightItem setTitle:@"取消" forState:UIControlStateNormal];
    [rightItem setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightItem.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightItem addTarget:self action:@selector(cancleBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightItem];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    CGFloat searchWidth = self.view.width - 73;
    CGFloat searchHeight = 25;
    GQHomeSearchBar *searchBar = [[GQHomeSearchBar alloc] init];
    self.searchBar = searchBar;
    searchBar.x = 10;
    searchBar.y = self.navigationController.navigationBar.height - kSearchMargin - searchHeight;
    searchBar.width = searchWidth;
    searchBar.height = searchHeight;
    searchBar.placeholder = @"搜索";
    [self.navigationController.navigationBar addSubview:searchBar];
    self.coverView.alpha = 1;
    
    
}

- (UIView *)coverView
{
    if (_coverView == nil) {
        UIView *coverView = [[UIView alloc] initWithFrame:CGRectMake(0, kNavigatationBarHeight, kScreenWidth, kScreenHeight - kNavigatationBarHeight)];
        
        CGFloat lable1Width = 120;
        coverView.backgroundColor = [UIColor colorWithRed:236/255.0 green:236/255.0 blue:236/255.0 alpha:1.0];
        
        UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake((self.view.width - lable1Width) / 2, 75, 120, 25)];
        label1.font = [UIFont systemFontOfSize:20];
        label1.text = @"搜索你感兴趣";
        label1.textColor = [UIColor lightGrayColor];
        [coverView addSubview:label1];
        
        CGFloat label2Width = 150;
        UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake((self.view.width - label2Width) / 2, CGRectGetMaxY(label1.frame), label2Width, 14)];
        label2.font = [UIFont systemFontOfSize:16];
        label2.textColor = [UIColor lightGrayColor];
        label2.text = @"藏友-状态-标签-资讯";
        [coverView addSubview:label2];
        [self.view addSubview:coverView];
        
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognizerClick)];
        [coverView addGestureRecognizer:tapGestureRecognizer];
        
    }
    return _coverView;
    
}

- (void)tapGestureRecognizerClick
{
    [self.searchBar endEditing:YES];
}

- (void)cancleBtnClick
{
    [UIView animateWithDuration:0.5 animations:^{
        self.searchBar.alpha = 0;
    } completion:^(BOOL finished) {
        [self.searchBar removeFromSuperview];
        self.searchBar = nil;
    }];
    [self.searchBar removeFromSuperview];
    self.searchBar = nil;
    [self.navigationController popViewControllerAnimated:YES];
    
}

@end
